package com.itheima.mq.listener;

import cn.hutool.json.JSONUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.commons.pojo.entity.PublishCheckLog;
import com.itheima.dubbo.interfaces.PublishCheckLogApi;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @author yaohu
 * @date 2021/12/20
 * @Version 1.0
 * @describe
 */
@Component
@RocketMQMessageListener(consumerGroup = "cp1", topic = "check_log")
public class CheckLogListener implements RocketMQListener<String> {

    @Reference
    private PublishCheckLogApi publishCheckLogApi;

    @Override
    public void onMessage(String message) {
        System.out.println("接到信息了check_log");
        PublishCheckLog publishCheckLog = JSONUtil.toBean(message, PublishCheckLog.class);
        publishCheckLogApi.savePublishCheckLog(publishCheckLog);
    }
}
